package com.itheima.controller.backend;

import com.itheima.DTO.OrderDTO;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.Result;
import com.itheima.pojo.Order;
import com.itheima.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
@Slf4j
@Api(tags = "预约管理")
public class OrderController {
    @Autowired
    private OrderService orderService;


    /**
     * 分页查询预约信息
     * @param orderDTO
     * @return
     */
    @PostMapping("/findPage")
    @ApiOperation(value ="分页查询")
    public PageResult findPage(@RequestBody OrderDTO orderDTO){
        log.info("分页查询预约信息:{}",orderDTO);
        PageResult pageResult = orderService.pageQuery(orderDTO);

        return pageResult;
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改状态")
    public Result update(@RequestBody Order OrderDTO){
        log.info("修改预约状态:{}",OrderDTO);
        int stutas = orderService.update(OrderDTO);
        if (stutas == 1){
            return new Result(true,"预约状态修改成功");
        }else {
            return new Result(false,"预约状态修改失败");
        }
    }

}


